<!DOCTYPE html>
<html lang="zh-CN">

<!-- 文档头部 -->
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="个人主页 - 登录页面">
    <meta name="theme-color" content="#3B82F6">
    <meta name="author" content="张小明">
    
    <!-- 标题 -->
    <title>登录 | 个人主页管理</title>
    
    <!-- 外部样式表 -->
    <link rel="stylesheet" href="styles.css">
    
    <!-- 登录页面特定样式 -->
    <style>
        /* 登录页面布局 */
        .login-container {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            background: linear-gradient(135deg, #EFF6FF 0%, #EEF2FF 100%);
        }
        
        .login-header {
            background-color: rgba(255, 255, 255, 0.95);
            padding: 1rem;
            box-shadow: var(--shadow);
        }
        
        .login-content {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 2rem 1rem;
        }
        
        .login-card {
            background-color: var(--white);
            border-radius: 8px;
            box-shadow: var(--shadow);
            padding: 2rem;
            width: 100%;
            max-width: 400px;
            transition: transform 0.3s ease;
        }
        
        .login-card:hover {
            transform: translateY(-5px);
            box-shadow: var(--shadow-hover);
        }
        
        .login-title {
            text-align: center;
            margin-bottom: 1.5rem;
            color: var(--dark);
            font-size: 1.75rem;
        }
        
        .login-form .form-group {
            margin-bottom: 1.5rem;
        }
        
        .login-form label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 500;
            color: var(--dark);
        }
        
        .login-form input {
            width: 100%;
            padding: 0.75rem 1rem;
            border: 1px solid #E5E7EB;
            border-radius: 4px;
            font-size: 1rem;
            transition: var(--transition);
            background-color: var(--light);
        }
        
        .login-form input:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
        }
        
        .login-form input.error {
            border-color: #EF4444;
        }
        
        .error-message {
            color: #EF4444;
            font-size: 0.875rem;
            margin-top: 0.25rem;
        }
        
        .login-form .login-button {
            width: 100%;
            padding: 0.75rem;
            background-color: var(--primary);
            color: var(--white);
            border: none;
            border-radius: 4px;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: var(--transition);
        }
        
        .login-form .login-button:hover {
            background-color: #2563EB;
            transform: translateY(-2px);
            box-shadow: var(--shadow);
        }
        
        .login-form .login-button:active {
            transform: translateY(0);
        }
        
        .login-links {
            text-align: center;
            margin-top: 1.5rem;
        }
        
        .login-links a {
            color: var(--primary);
            text-decoration: none;
            transition: var(--transition);
        }
        
        .login-links a:hover {
            text-decoration: underline;
        }
        
        .login-footer {
            background-color: var(--dark);
            color: var(--white);
            text-align: center;
            padding: 1rem;
            font-size: 0.875rem;
        }
        
        /* 响应式设计 */
        @media (min-width: 768px) {
            .login-card {
                padding: 2.5rem;
            }
        }
    </style>
</head>

<body>
    <div class="login-container">
        <!-- 登录页面头部 -->
        <header class="login-header">
            <div class="container">
                <div class="navbar-container">
                    <a href="index.html" class="navbar-logo" aria-label="返回首页">
                        <span class="logo-icon">{ }</span>
                        <span>个人主页</span>
                    </a>
                </div>
            </div>
        </header>
        
        <!-- 登录表单区域 -->
        <main class="login-content">
            <div class="login-card">
                <h1 class="login-title">账户登录</h1>
                
                <form id="loginForm" class="login-form" novalidate>
                    <div class="form-group">
                        <label for="username">用户名</label>
                        <input 
                            type="text" 
                            id="username" 
                            name="username" 
                            placeholder="请输入用户名" 
                            required
                            autocomplete="username"
                        >
                        <div class="error-message"></div>
                    </div>
                    
                    <div class="form-group">
                        <label for="password">密码</label>
                        <input 
                            type="password" 
                            id="password" 
                            name="password" 
                            placeholder="请输入密码" 
                            required
                            autocomplete="current-password"
                        >
                        <div class="error-message"></div>
                    </div>
                    
                    <button type="submit" class="login-button">登录</button>
                    
                    <div class="login-links">
                        <a href="#">忘记密码？</a>
                    </div>
                </form>
            </div>
        </main>
        
        <!-- 登录页面页脚 -->
        <footer class="login-footer">
            <p>© 2023 个人主页管理系统. 保留所有权利.</p>
        </footer>
    </div>
    
    <!-- 登录页面脚本 -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const loginForm = document.getElementById('loginForm');
            
            // 表单验证函数
            function validateForm() {
                let isValid = true;
                
                // 重置所有错误信息
                document.querySelectorAll('.error-message').forEach(el => {
                    el.textContent = '';
                });
                
                document.querySelectorAll('input').forEach(input => {
                    input.classList.remove('error');
                });
                
                // 验证用户名
                const username = document.getElementById('username');
                if (!username.value.trim()) {
                    isValid = false;
                    username.classList.add('error');
                    username.nextElementSibling.textContent = '用户名不能为空';
                }
                
                // 验证密码
                const password = document.getElementById('password');
                if (!password.value) {
                    isValid = false;
                    password.classList.add('error');
                    password.nextElementSibling.textContent = '密码不能为空';
                } else if (password.value.length < 6) {
                    isValid = false;
                    password.classList.add('error');
                    password.nextElementSibling.textContent = '密码长度不能少于6个字符';
                }
                
                return isValid;
            }
            
            // 处理表单提交
            loginForm.addEventListener('submit', function(event) {
                event.preventDefault();
                
                if (validateForm()) {
                    // 模拟登录成功，跳转到管理页面
                    // 在实际应用中，这里应该发送AJAX请求到服务器验证
                    alert('登录成功！将跳转到管理页面。');
                    window.location.href = 'admin.html';
                }
            });
            
            // 为输入框添加实时验证
            const inputs = loginForm.querySelectorAll('input');
            inputs.forEach(input => {
                input.addEventListener('input', function() {
                    if (this.classList.contains('error')) {
                        this.classList.remove('error');
                        this.nextElementSibling.textContent = '';
                    }
                });
                
                // 添加键盘事件，按Enter键可以切换到下一个输入框
                input.addEventListener('keydown', function(event) {
                    if (event.key === 'Enter') {
                        event.preventDefault();
                        const nextInput = this.closest('.form-group').nextElementSibling?.querySelector('input');
                        if (nextInput) {
                            nextInput.focus();
                        } else {
                            // 如果是最后一个输入框，则提交表单
                            loginForm.dispatchEvent(new Event('submit'));
                        }
                    }
                });
            });
        });
    </script>
</body>

</html>